package com.bawei.park2211a.fg


import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.base.bean.HomeEntity
import com.bawei.base.mvvm.BaseFragment

import com.bawei.park2211a.R
import com.bawei.park2211a.adapter.HomeAdapter
import com.bawei.park2211a.adapter.NoticeAdapter
import com.bawei.park2211a.databinding.FragmentHomeBinding
import com.bawei.park2211a.fg.home.HomeViewModel

import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>() {
    private lateinit var homeAdapter: HomeAdapter
    private lateinit var noticeAdapter: NoticeAdapter
    override fun initView() {
        val list = mutableListOf<HomeEntity>()
        list.add(HomeEntity(R.drawable.stall, "车位管理"))
        list.add(HomeEntity(R.drawable.notice, "车位管理"))
        list.add(HomeEntity(R.drawable.stall, "车位管理"))
        list.add(HomeEntity(R.drawable.alarmclock, "车位管理"))
        list.add(HomeEntity(R.drawable.house, "车位管理"))
        list.add(HomeEntity(R.drawable.store, "车位管理"))
        list.add(HomeEntity(R.drawable.vip, "车位管理"))
        list.add(HomeEntity(R.drawable.devicemanagement, "车位管理"))
        homeAdapter = HomeAdapter()
        homeAdapter.setNewData(list)
        binding.homeRec1.adapter = homeAdapter
        binding.homeRec1.layoutManager = GridLayoutManager(requireContext(), 4)
        viewModel.notice(0, 10)
        noticeAdapter = NoticeAdapter()
        binding.homeRec2.adapter = noticeAdapter
        binding.homeRec2.layoutManager = LinearLayoutManager(requireContext())
        homeAdapter.setOnItemClickListener { _, _, position ->
            when (position) {
                0 -> {
                    ARouter.getInstance().build("/app/car/CarActivity").navigation()
                }
                1 -> {
                    ARouter.getInstance().build("/vehicle/VehicleActivity").navigation()
                }
                3 -> {
                    ARouter.getInstance().build("/user/UserActivity").navigation()
                }
                5 -> {
                    ARouter.getInstance().build("/company/CompanyActivity").navigation()
                }
            }

        }

    }

    override fun initData() {
        viewModel.noticrSuccess.observe(this) {
            noticeAdapter.setNewData(it)
            noticeAdapter.notifyDataSetChanged()
        }
    }
}